home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lh211src.zip / LIST.C < prev    next >
C/C++ Source or Header  |  1990-09-30  |  2KB  |  104 lines

  1. /***********************************************************
  2.     list.c -- list files in archive
  3. ***********************************************************/
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include "lh.h"
  8.  
  9. static int filecount;
  10. static long originalsize, packedsize;
  11.  
  12. void initlist(void)
  13. {
  14.     filecount = originalsize = packedsize = 0;
  15.     if (flg_n == 0) {
  16.         printf("  Name          Original    Packed  Ratio"
  17.                "   Date     Time   Attr Type  CRC\n");
  18.         printf("--------------  --------  -------- ------"
  19.                " -------- -------- ---- ----- ----\n");
  20.     }
  21. }
  22.  
  23. static void expanddate(char *buf, time_t t, ulong org, ulong pac)
  24. {
  25.     struct tm *tm;
  26.     int rt;
  27.  
  28.     tm = localtime(&t);
  29.     rt = ratio(pac, org, 3);
  30.     sprintf(buf + 14, "%10lu%10lu %3d.%1d%% "
  31.         "%02d-%02d-%02d %02d:%02d:%02d",
  32.         org, pac, rt / 10, rt % 10,
  33.         tm -> tm_year % 100,
  34.         tm -> tm_mon + 1,
  35.         tm -> tm_mday,
  36.         tm -> tm_hour,
  37.         tm -> tm_min,
  38.         tm -> tm_sec);
  39. }
  40.  
  41. void list(void)
  42. {
  43.     char buf[79], *p, *q;
  44.     static char attr[7] = "ohs--a";
  45.     int i, j, k;
  46.  
  47.     p = hpb.filename;
  48.     q = hpb.pathname;
  49.     if (flg_n == 0) {
  50.         memset(buf, ' ', 14);
  51.         expanddate(buf, hpb.utc, hpb.original, hpb.packed);
  52.         sprintf(buf + 59, " ---w       %04X", hpb.filecrc);
  53.         memcpy(&buf[65], hpb.method, 5);
  54.         for (i = 0, j = 1; i < 6; i++, j <<= 1) {    /* attributes */
  55.             if (hpb.attr & j) {
  56.                 k = attr[i];
  57.                 if (i <= 2) {
  58.                     buf[63 - i] = k;
  59.                 } else {
  60.                     buf[60] = k;
  61.                 }
  62.             }
  63.         }
  64.         if (hpb.level < 0) {
  65.             memset(&buf[71], '*', 4);    /* if no CRC suppoted */
  66.         }
  67.         if (flg_x) {
  68.             puts(q);    /* display in 2 lines */
  69.         } else {
  70.             if (p != q) {        /* display in one line */
  71.                 *buf = '+';
  72.             }
  73.             memcpy(&buf[2], p, strlen(p));
  74.         }
  75.         puts(buf);
  76.         filecount ++;
  77.         originalsize += hpb.original;
  78.         packedsize += hpb.packed;
  79.     } else {
  80.         if (flg_x) {
  81.             puts(q);
  82.         } else {
  83.             puts(p);
  84.         }
  85.     }
  86. }
  87.  
  88. void endlist(time_t arctime)
  89. {
  90.     char buf[79];
  91.  
  92.     if (flg_n == 0) {
  93.         if (filecount) {
  94.             printf("--------------  --------  -------- ------"
  95.                    " -------- --------\n");
  96.             sprintf(buf, "   %3d files  ", filecount);
  97.             expanddate(buf, arctime, originalsize, packedsize);
  98.             puts(buf);
  99.         } else {
  100.             printf("  no file\n");
  101.         }
  102.     }
  103. }
  104.